﻿using Sustainalytics.Entities;
using System;

namespace Sustainalytics.Accounts.Service.Models
{
    public class AccountDto
    {
        public Guid Id { get; set; }

        public Guid CurrentEsgProfile { get; set; }

        public Guid UpcomingEsgProfile { get; set; }

        public string Name { get; set; }

        public string RelationshipType { get; set; }

        public string AccountManager { get; set; }

        public string Status { get; set; }

        public string Office { get; set; }

        public DateTime LastSyncWithCRM { get; set; }        

        private AccountDto() { }

        public static AccountDto CreateComplete(Account account)
        {
            if (account == null)
                throw new ArgumentNullException("account", "Account cannot be null.");

            return new AccountDto()
            {
                Id = account.Id,
                CurrentEsgProfile =  account.CurrentEsgProfile,
                UpcomingEsgProfile = account.UpcomingEsgProfile.GetValueOrDefault(),
                AccountManager = account.AccountManager != null ? account.AccountManager.FullName : "",
                Name = account.Name,
                Office = account.Office,
                RelationshipType = account.RelationshipType.ToString(),
                Status = account.Status.ToString(),
                LastSyncWithCRM = account.LastCrmSync,
            };
        }

        public static object CreateWithNameIdTypeManagerStatus(Account account)
        {
            if (account == null)
                throw new ArgumentNullException("account", "Account cannot be null.");

            return new
            {
                Id = account.Id,
                Name = account.Name,
                AccountManager = account.AccountManager != null ? account.AccountManager.FullName : "",
                RelationshipType = account.RelationshipType.ToString(),
                Status = account.Status.ToString(),
                PlatformTier = account.PlatformTier
            };
        }

        public static object CreateWithNameId(Account account)
        {
            if (account == null)
                throw new ArgumentNullException("account", "Account cannot be null.");

            return new
            {
                Id = account.Id,
                Name = account.Name,
            };
        }
    }
}
